//
//  MapLayer.m
//  Eliminator
//
//  Created by Rocky on 12-10-14.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "MapLayer.h"
#import "CCLabelTTF.h"
#import "CCMenu.h"
#import "CCMenuItem.h"
#import "CCDirector.h"
#import "CCSprite.h"
#import "CCTextureCache.h"

@implementation MapLayer

- (id)init
{
    self = [super init];
    if (self) {
        
        CGSize size = [[CCDirector sharedDirector] winSize];
        CCTexture2D *texture = [[CCTextureCache sharedTextureCache] addImage:@"grass.png"];

        CCSprite *sprite = [CCSprite spriteWithTexture:texture rect:CGRectMake(0, 0, size.width, size.height)];
        sprite.position = CGPointMake(size.width / 2, size.height / 2);
        ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
        [sprite.texture setTexParameters:&params];
        [self addChild:sprite];
        
//        for (int j = 0; j < 6 ; j++) {
//            
//            for (int i = 0 ; i < 10; i++) {
//                
//                // 图片上有五个子图，取第imageIndex个
//                int imageIndex = (i + j) % 5;
//                CCSprite *sprite = [CCSprite spriteWithTexture:texture rect:CGRectMake(0, imageIndex * 48, 48, 48)];
//                sprite.position = CGPointMake(480 - 24 - i * 48, 24 + j * 48);
//                [self addChild:sprite];
//            }    
//        }
                
        
        // 菜单		
		[CCMenuItemFont setFontSize:28];		
        
		CCMenuItem *backItem = [CCMenuItemFont itemWithString:@"返回" block:^(id sender) {
            DLog(@"返回");
            self.zOrder = -1 * self.zOrder;
		}];
        
		CCMenu *menu = [CCMenu menuWithItems:backItem, nil];
		
		[menu alignItemsVerticallyWithPadding:20.0f];
		[menu setPosition:CGPointMake(size.width/2, size.height/2)];     
//        [self addChild:menu];
        
    }
    
    return self;
}

- (void)draw {
    
}

@end
